package com.jlu.yygh.controller.api;

import com.jlu.yygh.common.result.Result;
import com.jlu.yygh.model.hosp.Hospital;
import com.jlu.yygh.service.DepartmentService;
import com.jlu.yygh.service.HospitalService;
import com.jlu.yygh.service.HospitalSetService;
import com.jlu.yygh.service.ScheduleService;
import com.jlu.yygh.vo.hosp.HospitalQueryVo;
import com.jlu.yygh.vo.hosp.ScheduleOrderVo;
import com.jlu.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

  @Autowired
  private HospitalService hospitalService;

  @Autowired
  private DepartmentService departmentService;

  @Autowired
  private ScheduleService scheduleService;

  @Autowired
  private HospitalSetService hospitalSetService;

  @ApiOperation(value = "获取分页列表")
  @GetMapping("findHospList/{page}/{limit}")
  public Result findHospList(
          @PathVariable Integer page,
          @PathVariable Integer limit,
          HospitalQueryVo hospitalQueryVo) {
    Page<Hospital> hospitals = hospitalService.selectPage(page, limit, hospitalQueryVo);
    return Result.ok(hospitals);
  }

  @ApiOperation(value = "根据医院名称获取医院列表")
  @GetMapping("findByHosname/{hosname}")
  public Result findByHosname(
          @PathVariable String hosname) {
    return Result.ok(hospitalService.findByHosname(hosname));
  }

  @ApiOperation(value = "根据医院编号获取科室列表")
  @GetMapping("department/{hoscode}")
  public Result index(@PathVariable String hoscode) {
    return Result.ok(departmentService.findDeptTree(hoscode));
  }

  @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
  @GetMapping("{hoscode}")
  public Result item(@PathVariable String hoscode) {
    return Result.ok(hospitalService.item(hoscode));
  }

//  获取所有可预约排班数据
  @ApiOperation(value = "获取所有可预约排班数据")
  @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
  public Result getBookingSchedule(
          @PathVariable Integer page,
          @PathVariable Integer limit,
          @PathVariable String hoscode,
          @PathVariable String depcode) {
    return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
  }
//  获取单个排班的数据
  @ApiOperation(value = "获取排班数据")
  @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
  public Result findScheduleList(
          @PathVariable String hoscode,
          @PathVariable String depcode,
          @PathVariable String workDate) {
    return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
  }

  @ApiOperation(value = "根据排班id获取排班数据")
  @GetMapping("getSchedule/{scheduleId}")
  public Result getSchedule(@PathVariable String scheduleId) {
    return Result.ok(scheduleService.getById(scheduleId));
  }

  @ApiOperation(value = "根据排班id获取预约下单数据")
  @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
  public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
    return scheduleService.getScheduleOrderVo(scheduleId);
  }

  @ApiOperation(value = "获取医院签名信息")
  @GetMapping("inner/getSignInfoVo/{hoscode}")
  public SignInfoVo getSignInfoVo(@PathVariable("hoscode") String hoscode) {
    return hospitalSetService.getSignInfoVo(hoscode);
  }
}
